package com.costmary.spper.action;

import com.costmary.spper.model.Weather;
import com.costmary.spper.util.WeatherFormatter;
import com.costmary.spper.util.YahooParser;
import com.costmary.spper.util.YahooRetriever;
import org.apache.log4j.PropertyConfigurator;

import java.io.InputStream;

/**
 * Created by IntelliJ IDEA.
 * User: sen
 * Date: 2010-9-18
 * Time: 23:05:51
 * To change this template use File | Settings | File Templates.
 */
public class WeatherAction {
    public WeatherAction(int zip) {
        this.zip = zip;
    }


    private int zip;

    public static void main(String[] args) throws Exception {
        PropertyConfigurator.configure(WeatherAction.class.getClassLoader().getResource("log4j.properties"));
        int zipcode = 60202;
        try {
            zipcode = Integer.parseInt(args[0]);
        } catch (Exception e) {
            new WeatherAction(zipcode).start();
        }
    }

    public void start() throws Exception {
        System.out.println("start");
// Retrieve Data
        InputStream dataIn = new YahooRetriever().retrieve(zip);
// Parse Data
        Weather weather = new YahooParser().parse(dataIn);
// Format (Print) Data
        System.out.print(new WeatherFormatter().format(weather));
    }
}
